﻿using SIR.Common;
using SIR.Common.Condition;
using SIR.Entities.Interfaces;
using System.Linq;

namespace SIR.Entities.Implementations
{
	/// <summary>
	/// Identifies an association between an image and a pattern
	/// </summary>
	public class ImagePattern : Entity, IImagePattern
	{
		/// <summary>
		/// Gets or sets the identifier for the image
		/// </summary>
		[DatabaseAccess(DatabaseAccessRights.ReadWrite)]
		public long ImageId { get; set; }
		/// <summary>
		/// Gets or sets the identifier for the pattern description
		/// </summary>
		[DatabaseAccess(DatabaseAccessRights.ReadWrite)]
		public long PatternDescriptionId { get; set; }
		/// <summary>
		/// Gets or sets the percentage that the image matches the pattern
		/// </summary>
		[DatabaseAccess(DatabaseAccessRights.ReadWrite)]
		public decimal MatchPercentage { get; set; }

		private IPatternDescription _patternDescription;
		/// <summary>
		/// Gets the pattern description for the image-pattern association
		/// </summary>
		[Newtonsoft.Json.JsonIgnore]
		[DatabaseAccess(DatabaseAccessRights.None)]
		public IPatternDescription Description
		{
			get
			{
				if (_patternDescription == null)
				{
					_patternDescription = DAL.DataServer.Find<PatternDescription>(new Predicate("Id", PatternDescriptionId, PredicateOperator.EqualTo)).Results.FirstOrDefault();
				}
				return _patternDescription;
			}
		}
	}
}

